Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
How to "conventionally" (without class syntax) call a superconstructor in javascript that enforces the use of "new"?

I'd like to inherit some class MyClass from some built-in class Class in the conventional way, i.e. without the new "class" syntax. I'm used to the following:

MyClass.prototype = Object.create(Class.prototype);
function MyClass() {
   Class.apply(this, arguments); // calling the superconstructor => "TypeError: Class constructor: 'new' is required"
   ...
}
var myObject = new MyClass(...);

As indicated, for many newer classes, usage of "new" with the constructor is enforced (e.g. for MediaSource). But new will be used with MyClass and will already have created a new object, so that I should not create yet another object inside the constructor. What am I supposed to do, or what is the equivalent here of the super() call in the new class syntax?

The only way I could think of, is to indeed create an instance with new Class() and explicitly return this instance from the constructor. But then the prototype of MyClass (which might have additional properties) is not really used ...

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda